<div class="fm-content">
  <div class="title">
    <i nz-icon [type]="'desktop'"></i>
    &nbsp;&nbsp;矢量数据
  </div>
  <div class="work">
    <div class="top">
      <input nz-input placeholder="名称" class="fm-input first-input" [(ngModel)]="fs.queryObject['dataname:like']" />
      <nz-select [(ngModel)]="fs.queryObject['datatype']" (nzOpenChange)="layerTypeDic.load('0')" class="fm-input"
        [nzPlaceHolder]="'类型'">
        <nz-option *ngFor="let option of layerTypeDic.datas" [nzLabel]="option.display" [nzValue]="option.id">
        </nz-option>
        <nz-option *ngIf="layerTypeDic.isLoading" nzDisabled nzCustomContent>
          <i nz-icon type="loading" class="loading-icon"></i>加载中...
        </nz-option>
      </nz-select>
      <nz-button-group class="fm-search-input">
        <button nz-button nzType="primary" (click)="fs.loadData(true)">查询</button>
        <button nz-button (click)="fs.resetQueryObject() && fs.loadData(true)">重置</button>
      </nz-button-group>
      <div class="tool-right">
        <nz-button-group>
          <button nz-button [nzType]="'primary'" (click)="fs.addRow()">新增</button>
          <button nz-button (click)="fs.editRow()">编辑</button>
          <button nz-popconfirm nzTitle="确认删除选择项?" (nzOnConfirm)="fs.delEntitys()" nzPlacement="bottomRight"
            nz-button>删除</button>
        </nz-button-group>
      </div>
    </div>

    <div class="work-content">
      <div class="table">
        <nz-table nzSize="middle" nzShowSizeChanger [nzPageSizeOptions]='[ 10, 15, 20, 30, 40, 50 ]'
          [nzFrontPagination]="false" [nzData]="[{}]" [nzLoading]="fs.isLoading || fs.isDeleing"
          [nzTotal]="fs.rowsCount" [(nzPageIndex)]="fs.pageIndex" [(nzPageSize)]="fs.pageSize"
          (nzPageIndexChange)="fs.loadData()" (nzPageSizeChange)="fs.loadData(true)">
          <thead>
            <tr>
              <th nzShowCheckbox [(nzChecked)]="fs.allChecked" [nzIndeterminate]="fs.indeterminate"
                (nzCheckedChange)="fs.checkAll($event)"></th>
              <th>名称</th>
              <th>类型</th>
              <th>元数据</th>
              <th>有效</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of fs.datas">
              <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="fs.refreshCheckStatus()">
              </td>
              <td><span (click)="fs.editRow(data)" class="form-edit">{{data.dataname}}<br />({{data.id}})</span></td>
              <td>{{data.datatypename}}</td>
              <td>{{data.metadataName}}</td>
              <td>{{data.valid | boolReform}}</td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>

    <nz-modal nzWidth='830' nzTitle="编辑" [nzMaskClosable]='false' [nzFooter]="null" [(nzVisible)]="fs.isEditVisible"
      (nzOnCancel)="fs.closeEdit()">
      <form nz-form [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">标识</nz-form-label>
              <nz-form-control class="form-control3" [nzValidateStatus]="id.invalid?'error':'success'" nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.id" [disabled]="!fs.er.FIELD_ISNEW" id="id" name="id"
                  #id="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">名称</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input required [(ngModel)]="fs.er.dataname" id="dataname" name="dataname" #dataname="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">类型</nz-form-label>
              <nz-form-control class="form-control">
                <nz-select [(ngModel)]="fs.er.datatype" name="datatype" required #datatype="ngModel"
                  (nzOpenChange)="layerTypeDic.load('0')" [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of layerTypeDic.datas" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="layerTypeDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                  <span *ngIf="!layerTypeDic.isLoaded">
                    <nz-option [nzLabel]="fs.er.datatypename" [nzValue]="fs.er.datatype">
                    </nz-option>
                  </span>
                </nz-select>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <!-- <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">表空间名</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.tableSpace" name="tableSpace">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div> -->
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">数据表名</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.datatable" name="datatable">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">元数据</nz-form-label>
              <nz-form-control class="form-control">
                <nz-tree-select nzPlaceHolder="请选择" [nzDropdownMatchSelectWidth]="true"
                  [nzDropdownStyle]="{ 'max-height': '300px' }" [(ngModel)]="fs.er.metadata" name="metadata"
                  [nzAsyncData]="true" [nzNodes]="metadataDic.treeDatas">
                </nz-tree-select>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">空间参考</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.spatialReference" name="spatialReference">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">主键字段</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.objectIdFieldName" name="objectIdFieldName">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">政区字段</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input placeholder="市,县,乡,村" [(ngModel)]="fs.er.adminFields" name="adminFields">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">附件字段</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input placeholder="" [(ngModel)]="fs.er.imageField" name="imageField">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>


        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">外部数据库</nz-form-label>
              <nz-form-control class="form-control">
                <nz-switch nzCheckedChildren="是" nzUnCheckedChildren="否" [(ngModel)]="fs.er.outdatabase"
                  name="outdatabase">
                </nz-switch>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="fs.er.outdatabase">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">驱动</nz-form-label>
              <nz-form-control class="form-control3">
                <input nz-input [(ngModel)]="fs.er.driver" name="driver">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="fs.er.outdatabase">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">url</nz-form-label>
              <nz-form-control class="form-control3">
                <input nz-input [(ngModel)]="fs.er.url" name="url">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="fs.er.outdatabase">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">用户名</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.username" name="username">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">密码</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="fs.er.password" name="password">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <!-- <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">子表集</nz-form-label>
              <nz-form-control class="form-control3">
                <input nz-input [(ngModel)]="fs.er.subtable" name="subtable">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div> -->
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">排序</nz-form-label>
              <nz-form-control class="form-control">
                <nz-input-number required [(ngModel)]="fs.er.order" name="order" [nzMin]="1" #order="ngModel"
                  [nzStep]="1" class="form-control">
                </nz-input-number>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">有效</nz-form-label>
              <nz-form-control class="form-control">
                <nz-switch nzCheckedChildren="有" nzUnCheckedChildren="无" [(ngModel)]="fs.er.valid" name="valid">
                </nz-switch>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">子表集</nz-form-label>
              <nz-form-control class="form-control3">
                <nz-table #childTable [nzData]="[{}]" [nzShowPagination]='false'>
                  <thead>
                    <tr>
                      <th nzWidth="15%">排序</th>
                      <th nzWidth="30">表名称</th>
                      <th nzWidth="30%">外键</th>
                      <th>
                        <span class="form-edit" (click)="fs.addLocalRow(fs.er, 'subs', ['id'])">
                          <添加行>
                        </span>
                      </th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr *ngFor="let c of fs.er.subs">
                      <td>
                        <input type="text" nz-input [(ngModel)]="c.order" [ngModelOptions]="{standalone: true}" />
                      </td>
                      <td>
                        <nz-select class="form-control" [ngModelOptions]="{standalone: true}" [(ngModel)]="c.defID"
                          [nzPlaceHolder]="'请选择'">
                          <nz-option *ngFor="let option of defDic.datas" [nzLabel]="option.display"
                            [nzValue]="option.id">
                          </nz-option>
                        </nz-select>
                        <!-- <input type="text" nz-input [(ngModel)]="c.defID" [ngModelOptions]="{standalone: true}" /> -->
                      </td>
                      <td>
                        <input type="text" nz-input [(ngModel)]="c.foreignKey" [ngModelOptions]="{standalone: true}" />
                      </td>
                      <td>
                        <span class="form-edit" nz-popconfirm nzTitle="确认删除选择项?"
                          (nzOnConfirm)="fs.delLocalRow(fs.er.items, c)" nzPlacement="bottomRight">删除</span>
                      </td>
                    </tr>
                  </tbody>
                </nz-table>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" class="form-button-align">
            <button nz-button nzType="default" (click)="fs.closeEdit()" class="form-button">取消</button>
            <button nz-button nzType="primary" [disabled]='dataname.invalid || datatype.invalid || order.invalid'
              (click)="fs.save()" [nzLoading]="fs.isSaveing">保存</button>
          </div>
        </div>
      </form>
    </nz-modal>
  </div>
</div>